import os  
  
def get_file_paths(directory):  
    file_paths = []  # list of file paths  
  
    for foldername, subfolders, filenames in os.walk(directory):  
        for filename in filenames:  
            if filename.endswith('.jpg'):  # change to match your file type  
                file_paths.append(os.path.join(foldername, filename))  
  
    return file_paths  
  
def write_paths_to_file(file_paths, output_file):  
    with open(output_file, 'w') as f:  
        for path in file_paths:  
            f.write(path + '\n')  
  
directory = 'D:/PythonProjects/yolov5-1.0/revised_hot_work_classes6_task2/images/train'  # replace with your directory path  
output_file = 'D:/PythonProjects/yolov5-1.0/revised_hot_work_classes6_task2/train.txt'  # replace with your output file name  

file_paths = get_file_paths(directory)  
write_paths_to_file(file_paths, output_file)